package com.tc.juc.pack06;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * @Auther: tianchao
 * @Date: 2021/10/6 21:10
 * @Description:
 */
@Slf4j
public class Test40 {
    public static void main(String[] args) {
        Student stu = new Student();
        AtomicReferenceFieldUpdater updater = AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");
        updater.compareAndSet(stu, null, "A");
        System.out.println(stu);
    }
}
class Student{
    volatile String name;

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                '}';
    }
}
